export default {
  state: {
    authList: [],
    menuList: [],
    hashRouter: false,
    dbClickId: "",
    tabsValue: window.sessionStorage.getItem("tabsValue") ? window.sessionStorage.getItem("tabsValue") : "/home/index",
    tabs: window.sessionStorage.getItem("tabs") ? JSON.parse(window.sessionStorage.getItem("tabs")) : [{
      name: "/home/index",
      title: "首页介绍"
    }]
  },
  mutations: {
    reset(state) {
      state.authList = []
      state.menuList = []
      state.hashRouter = false
      state.tabsValue = "/home/index"
      state.tabs = [{
        name: "/home/index",
        title: "首页介绍"
      }]
    },
    setdbClickId(state, id) {
      state.dbClickId = id
    },
    setMenuList(state, menuList) {
      state.menuList = menuList
      localStorage.setItem('menuList',JSON.stringify(menuList))
    },
    closeAll(state){
      state.tabsValue = "/home/index"
      state.tabs = [{
        name: "/home/index",
        title: "首页介绍"
      }]
    },
    closeOther(state){
      state.tabs=state.tabs.filter(item=>item.name==state.tabsValue)
    },
    setAuthList(state, authList) {
      state.authList = authList
      localStorage.setItem('authList',JSON.stringify(authList))
    },
    setHashRouter(state, router) {
      state.hashRouter = router
    },
    setTabs(state, tab) {
      // console.log(tab,123)
      let flag = true
      //是否需要新增
      state.tabs.map(item => {
        if (item.title == tab.title) flag = false
      })
      if (flag) state.tabs.push(tab)
      state.tabsValue = tab.name
    },
    changeTabs(state, payload) { //删除的值两种情况 一种是当前存活的标签 一种是死去的
    console.log(payload)
      state.tabs.map((item, index) => {
        if (item.name == payload.target && state.tabs.length > 1) {
          state.tabs.splice(index, 1)
          if (payload.flag) state.tabsValue = state.tabs[index - 1].name//当删除的是存活的page页时需要-1，让前一个获取焦点
        }
      })
    },
    removeAnalogueTab(state,RegName){
      state.tabs.map((item,index)=>{
        // console.log("item:"+item.name)
        // console.log("reg"+RegName)
        if(item.name.indexOf(RegName)!=-1){
          console.log(index);
          console.log('shanchu')
          state.tabs.splice(index, 1)
          console.log(state.tabs);
          state.tabsValue = state.tabs[index - 1].name
          console.log(state.tabsValue);
        }
       
      })
    },
    setTabsValue(state, value) {
      state.tabsValue = value
    }
  }
}
